package sg.edu.nus.iss.jass.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 * <h5>FunctionPanel to load the actual function GUI form</h5>
 * This  class is derived from JPanel to create the actual function GUI form.This class consists of 
 * HeaderPanel to show the Title of the Function and Message label to show resultant action message,
 * FormPanel to show the form for the user to fill in and 
 * ActionPanel to show the action buttons for the user to select the action on the form. 
 * @author Kafoor Sammil
 * 
 */

public class FunctionPanel extends JPanel  {

	/**
	 * 
	 */
	private static final long serialVersionUID = -525235180232648949L;
	private HeaderPanel headerPanel; 
	private FormPanel formPanel; 
	private ActionPanel actionPanel;
	
	
	/**
     * Constructor to create the Function Panel for the FormPanel passed as a argument .
     * @param formPanel
	 *            the actual FormPanel object to wrap with the FunctionPanel . 
     */ 
	public FunctionPanel(FormPanel formPanel) {
		super(null);
		setPreferredSize(new Dimension((int) (MainFrame.WIDTH * 0.80),
				MainFrame.HEIGHT));
		setLayout(new BorderLayout());
		
		if(formPanel != null){
			this.formPanel = formPanel;
			this.headerPanel = formPanel.headerPanel;  
			this.actionPanel = formPanel.actionPanel; 
			
			
			if (this.headerPanel != null) {
				headerPanel.setPreferredSize(new Dimension(800, 80));
				add(this.headerPanel, BorderLayout.NORTH);
			}
			
			this.formPanel.setPreferredSize(new Dimension(800, 1200));
			JScrollPane scroller  = new JScrollPane(this.formPanel); 
			scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			add(scroller, BorderLayout.CENTER);
			
			if (this.actionPanel != null){
				add(this.actionPanel, BorderLayout.SOUTH);
			}
		}
	}
	
	/** 
	 * To get the current FormPanel Object
	 * @return the formPanel
	 */
	public FormPanel getFormPanel() {
		return this.formPanel;
	}
	
	/**
	 * To get the current HeaderPanel Object 
	 * @return the headerPanel
	 */
	public HeaderPanel getHeaderPanel() {
		return this.headerPanel;
	}
	
	/**
	 * To get the current ActionPanel Object  
	 * @return the actionPanel
	 */
	public ActionPanel getActionPanel() {
		return this.actionPanel;
	}
	
	/**
	 * To set the  HeaderPanel Object  
	 * @param headerPanel
	 * 			reference to the headerPanel
	 */
	public void setHeaderPanel(HeaderPanel headerPanel) {
		this.headerPanel = headerPanel;
	}
	
	/**
	 * To set the  ActionPanel Object  
	 * @param actionPanel
	 * 			reference to the actionPanel
	 */
	public void setActionPanel(ActionPanel actionPanel) {
		this.actionPanel = actionPanel;
		
	}

}
